package com.snow.java.base.junit;

import java.time.DayOfWeek;
import java.time.LocalDateTime;
import java.time.temporal.TemporalAdjusters;

/**
 * @类名称：
 * @类描述：
 * @author: bingHeng
 * @Date 2019.04.13
 * @Version: 1.0
*/
public class MyDateTime3 {

    /**
     * 时间器校正器：TemporalAdjuster。
     *  有时我们可能需要获取当前的时间的下个周日等操作，此时就需要用到该类
     *
     *  TemporalAdjusters:该类通过静态方法提供了大量的常用TemporalAdjuster的实现。
     */

    public static void main(String[] args) {
        LocalDateTime with = LocalDateTime.now().with(TemporalAdjusters.next(DayOfWeek.SUNDAY));
        System.out.println("下一个周日的日期为：" + with);

        // 自定义:下一个工作日
        LocalDateTime with1 = LocalDateTime.now().with((l) -> {
            LocalDateTime localDateTime = (LocalDateTime) l;
            DayOfWeek dayOfWeek = localDateTime.getDayOfWeek();
            if (dayOfWeek.equals(DayOfWeek.FRIDAY)) {
                return localDateTime.plusDays(3);
            } else if (dayOfWeek.equals(DayOfWeek.SATURDAY)) {
                return localDateTime.plusDays(2);
            } else {
                return localDateTime.plusDays(1);
            }
        });
        System.out.println(with1);

    }
}
